package com.itheima.web.controller;

import com.itheima.domain.db.Freeze;
import com.itheima.domain.db.UnFreeze;
import com.itheima.web.manager.UserManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.POST;
import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserManager userManager;

    @GetMapping("/manage/users")
    public ResponseEntity findUserinfoByPage(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                             @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return userManager.findUserinfoByPage(pageNum, pageSize);
    }

    //用户详情
    @GetMapping("/manage/users/{userId}")
    public ResponseEntity findUserInfoById(@PathVariable Long userId) {
        return userManager.findUserInfoById(userId);
    }


   // 动态列表
   @GetMapping("/manage/messages")
   public ResponseEntity findMovementVoByPage(
           @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
           @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
           @RequestParam(value = "uid", required = false) Long userId,
           Integer state) {
       return userManager.findMovementVoByPage(userId, state, pageNum, pageSize);
   }

    //动态详情
    @GetMapping("/manage/messages/{publishId}")
    public ResponseEntity findMovementVoById(@PathVariable String publishId) {
        return userManager.findMovementVoById(publishId);
    }

    //评论列表
    @GetMapping("/manage/messages/comments")
    public ResponseEntity findCommentVoByPage(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                              @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                              @RequestParam(value = "messageID") String publishId) {
        return userManager.findCommentVoByPage(pageNum, pageSize, publishId);
    }

    //视频列表
    @GetMapping("/manage/videos")
    public ResponseEntity findVideoByPage(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                          @RequestParam(value = "sortProp", defaultValue = "created") String sortProp,
                                          @RequestParam(value = "sortOrder", defaultValue = "desc") String sortOrder,
                                          @RequestParam(value = "uid") Long userId) {
        return userManager.findVideoByPage(pageNum, pageSize, sortProp, sortOrder, userId);
    }


    //冻结
    @PostMapping("/manage/users/freeze")
    public ResponseEntity freeze(@RequestBody Freeze freeze) {
       return userManager.saveFreeze(freeze);
    }

    //解冻
    @PostMapping("/manage/users/unfreeze")
    public ResponseEntity unFreeze(@RequestBody UnFreeze unFreeze) {
        return userManager.unFreeze(unFreeze);
    }

    //动态通过
    @PostMapping("/manage/messages/pass")
    public ResponseEntity passMovement(@RequestBody List<String> ids) {
        return userManager.passMovement(ids);
    }

    //动态拒绝
    @PostMapping("/manage/messages/reject")
    public ResponseEntity unPassMovement(@RequestBody List<String> ids) {
        return userManager.unPassMovement(ids);
    }

}
